# coding=utf-8
from flask import Flask

app = Flask(__name__)


class HeartBeat(object):
    """
    域控制器向中心控制器每隔几秒发心跳检测数据包,
    如果没有发，那么就认为域出现问题
    """

    @app.route("/heartbeat")
    def register(self):
        """
        域控制器调用这个API
        :return:
        """
        domain_id = request.json.get("domain_id")
        domain_ip = request.json.get("domain_ip")

        # 查看内存中是否有此domain
        if domain_id in domain_cache:
            # 有的话就更新其信任度
            domain_cache[domain_id] = 100
        else:
            log.error("Found a domain which not in cache: %s" % domain_id)
